home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / ov-typeinfo.cc < prev    next >
C/C++ Source or Header  |  1996-11-07  |  5KB  |  237 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "ov-typeinfo.h"
  32.  
  33. #include "defun.h"
  34. #include "error.h"
  35. #include "help.h"
  36. #include "oct-obj.h"
  37.  
  38. const int
  39. octave_value_typeinfo::init_tab_sz (16);
  40.  
  41. octave_value_typeinfo *
  42. octave_value_typeinfo::instance (0);
  43.  
  44. #include <Array.cc>
  45. #include <Array2.cc>
  46. #include <Array3.cc>
  47.  
  48. template class Array<binary_op_fcn>;
  49. template class Array2<binary_op_fcn>;
  50. template class Array3<binary_op_fcn>;
  51.  
  52. template class Array<assign_op_fcn>;
  53. template class Array2<assign_op_fcn>;
  54.  
  55. template class Array<type_conv_fcn>;
  56. template class Array2<type_conv_fcn>;
  57.  
  58. int
  59. octave_value_typeinfo::register_type (const string& name)
  60. {
  61.   if (! instance)
  62.     instance = new octave_value_typeinfo ();
  63.  
  64.   return instance->do_register_type (name);
  65. }
  66.  
  67. bool
  68. octave_value_typeinfo::register_binary_op (octave_value::binary_op op,
  69.                        int t1, int t2,
  70.                        binary_op_fcn f)
  71. {
  72.   if (! instance)
  73.     instance = new octave_value_typeinfo ();
  74.  
  75.   return instance->do_register_binary_op (op, t1, t2, f);
  76. }
  77.  
  78. bool
  79. octave_value_typeinfo::register_assign_op (int t_lhs, int t_rhs,
  80.                        assign_op_fcn f)
  81. {
  82.   if (! instance)
  83.     instance = new octave_value_typeinfo ();
  84.  
  85.   return instance->do_register_assign_op (t_lhs, t_rhs, f);
  86. }
  87.  
  88. bool
  89. octave_value_typeinfo::register_pref_assign_conv (int t_lhs, int t_rhs,
  90.                           int t_result) 
  91. {
  92.   if (! instance)
  93.     instance = new octave_value_typeinfo ();
  94.  
  95.   return instance->do_register_pref_assign_conv (t_lhs, t_rhs, t_result);
  96. }
  97.  
  98. bool
  99. octave_value_typeinfo::register_widening_op (int t, int t_result,
  100.                          type_conv_fcn f)
  101. {
  102.   if (! instance)
  103.     instance = new octave_value_typeinfo ();
  104.  
  105.   return instance->do_register_widening_op (t, t_result, f);
  106. }
  107.  
  108. int
  109. octave_value_typeinfo::do_register_type (const string& name)
  110. {
  111.   int i = 0;
  112.  
  113.   for (i = 0; i < num_types; i++)
  114.     if (name == types (i))
  115.       return i;
  116.  
  117.   int len = types.length ();
  118.  
  119.   if (i == len)
  120.     {
  121.       len *= 2;
  122.  
  123.       types.resize (len, string ());
  124.  
  125.       binary_ops.resize ((int) octave_value::num_binary_ops, len, len,
  126.              (binary_op_fcn) 0);
  127.  
  128.       assign_ops.resize (len, len, (assign_op_fcn) 0);
  129.  
  130.       pref_assign_conv.resize (len, len, -1);
  131.  
  132.       widening_ops.resize (len, len, (type_conv_fcn) 0);
  133.     }
  134.  
  135.   types (i) = name;
  136.  
  137.   num_types++;
  138.  
  139.   return i;
  140. }
  141.  
  142. bool
  143. octave_value_typeinfo::do_register_binary_op (octave_value::binary_op op,
  144.                           int t1, int t2,
  145.                           binary_op_fcn f)
  146. {
  147.   binary_ops.checkelem ((int) op, t1, t2) = f;
  148.  
  149.   return false;
  150. }
  151.  
  152. bool
  153. octave_value_typeinfo::do_register_assign_op (int t_lhs, int t_rhs,
  154.                           assign_op_fcn f)
  155. {
  156.   assign_ops.checkelem (t_lhs, t_rhs) = f;
  157.  
  158.   return false;
  159. }
  160.  
  161. bool
  162. octave_value_typeinfo::do_register_pref_assign_conv (int t_lhs, int t_rhs,
  163.                              int t_result) 
  164. {
  165.   pref_assign_conv.checkelem (t_lhs, t_rhs) = t_result;
  166.  
  167.   return false;
  168. }
  169.  
  170. bool
  171. octave_value_typeinfo::do_register_widening_op
  172.   (int t, int t_result, type_conv_fcn f)
  173. {
  174.   widening_ops.checkelem (t, t_result) = f;
  175.  
  176.   return false;
  177. }
  178.  
  179. #include <iostream.h>
  180.  
  181. binary_op_fcn
  182. octave_value_typeinfo::do_lookup_binary_op (octave_value::binary_op op,
  183.                         int t1, int t2)
  184. {
  185.   return binary_ops.checkelem ((int) op, t1, t2);
  186. }
  187.  
  188. assign_op_fcn
  189. octave_value_typeinfo::do_lookup_assign_op (int t_lhs, int t_rhs)
  190. {
  191.   return assign_ops.checkelem (t_lhs, t_rhs);
  192. }
  193.  
  194. int
  195. octave_value_typeinfo::do_lookup_pref_assign_conv (int t_lhs, int t_rhs)
  196. {
  197.   return pref_assign_conv.checkelem (t_lhs, t_rhs);
  198. }
  199.  
  200. type_conv_fcn
  201. octave_value_typeinfo::do_lookup_widening_op (int t, int t_result)
  202. {
  203.   return widening_ops.checkelem (t, t_result);
  204. }
  205.  
  206. string_vector
  207. octave_value_typeinfo::do_installed_type_names (void)
  208. {
  209.   string_vector retval (num_types);
  210.  
  211.   for (int i = 0;i < num_types; i++)
  212.     retval (i) = types (i);
  213.  
  214.   return retval;
  215. }
  216.  
  217. DEFUN (typeinfo, args, ,
  218.   "usage: typeinfo ([typename])")
  219. {
  220.   octave_value retval;
  221.  
  222.   int nargin = args.length ();
  223.  
  224.   if (nargin == 0)
  225.     retval = octave_value_typeinfo::installed_type_names ();
  226.   else
  227.     print_usage ("typeinfo");
  228.  
  229.   return retval;
  230. }
  231.  
  232. /*
  233. ;;; Local Variables: ***
  234. ;;; mode: C++ ***
  235. ;;; End: ***
  236. */
  237.